home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / C / code_locale.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  4.7 KB  |  138 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/types.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/nodes.h>
  7. #include <dos/dos.h>                    // dos
  8. #include <dos/dostags.h>
  9. #include <clib/exec_protos.h>           // protos
  10. #include <clib/dos_protos.h>
  11. #include <pragmas/exec_pragmas.h>       // pragmas
  12. #include <pragmas/dos_pragmas.h>
  13.  
  14. #include <string.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <ctype.h>
  18.  
  19. #include "DEV_IE:Generators/defs.h"
  20. #include "DEV_IE:Include/IEditor.h"
  21. #include "DEV_IE:Generators/C/Protos.h"
  22. ///
  23.  
  24.  
  25. /// WriteLocale
  26. void WriteLocale( struct GenFiles *Files, struct IE_Data *IE )
  27. {
  28.     UWORD               cnt;
  29.     struct ArrayNode   *ar;
  30.  
  31.     FPuts( Files->XDef, "extern void SetupLocale( void );\n"
  32.             "extern void LocalizeArray( UBYTE ** );\n"
  33.             "extern void LocalizeTags( ULONG *, UWORD );\n"
  34.             "extern void LocalizeList( struct MinList * );\n"
  35.             "extern void LocalizeGadgets( struct NewGadget *, ULONG *, UWORD *, UWORD );\n"
  36.             "extern void LocalizeMenus( struct NewMenu * );\n"
  37.             "extern void LocalizeITexts( struct IntuiText *, UWORD );\n"
  38.             "extern UBYTE GetActivationKey( STRPTR );\n" );
  39.  
  40.     FPrintf( Files->Std, "\nvoid SetupLocale( void )\n"
  41.              "{\n"
  42.              "\tUWORD\tcnt;\n\n"
  43.              "\tif( LocaleBase ) {\n"
  44.              "\t\tif( Catalog = OpenCatalog( NULL, \"%s.catalog\", OC_BuiltInLanguage, \"%s\", OC_Version, %ld, TAG_DONE )) {\n"
  45.              "\t\t\tfor( cnt = 0; cnt < ( sizeof( CatCompArray ) / sizeof( struct CatCompArrayType )); cnt++ )\n"
  46.              "\t\t\t\tCatCompArray[ cnt ].cca_Str = GetCatalogStr( Catalog, cnt, CatCompArray[ cnt ].cca_Str );\n"
  47.              "\t\t}\n"
  48.              "\t}\n",
  49.          IE->Locale->Catalog, IE->Locale->BuiltIn, IE->Locale->Version );
  50.  
  51.     for( cnt = 0, ar = IE->Locale->Arrays.mlh_Head; ar->Next; ar = ar->Next, cnt++ )
  52.     FPrintf( Files->Std, "\n\tLocalizeArray( &%s[0] );", ar->Label );
  53.  
  54.     FPuts( Files->Std, "\n}\n"
  55.                "\n"
  56.                "void LocalizeArray( UBYTE **Array )\n"
  57.                "{\n"
  58.                "\twhile( *Array ) {\n"
  59.                "\t\t*Array = (UBYTE *)CatCompArray[ (ULONG)*Array ].cca_Str;\n"
  60.                "\t\t*Array++;\n"
  61.                "\t}\n"
  62.                "}\n"
  63.                "\n"
  64.                "void LocalizeTags( ULONG *Tags, UWORD Kind )\n"
  65.                "{\n"
  66.                "\tULONG\ttag;\n\t"
  67.                "\tswitch( Kind ) {\n"
  68.                "\t\tcase\tSTRING_KIND:\n"
  69.                "\t\t\t\ttag = GTST_String;\n"
  70.                "\t\t\t\tbreak;\n"
  71.                "\t\tcase\tTEXT_KIND:\n"
  72.                "\t\t\t\ttag = GTTX_Text;\n"
  73.                "\t\t\t\tbreak;\n"
  74.                "\t\tcase\tNUMBER_KIND:\n"
  75.                "\t\t\t\ttag = GTNM_Format;\n"
  76.                "\t\t\t\tbreak;\n"
  77.                "\t\tcase\tSLIDER_KIND:\n"
  78.                "\t\t\t\ttag = GTSL_LevelFormat;\n"
  79.                "\t\t\t\tbreak;\n"
  80.                "\t\tdefault:\n"
  81.                "\t\t\t\treturn;\n"
  82.                "\t\t\t\tbreak;\n"
  83.                "\t}\n"
  84.                "\twhile(( *Tags != tag ) && ( *Tags ))\n"
  85.                "\t\tTags++;\n"
  86.                "\tif( *Tags++ )\n"
  87.                "\t\t*Tags = (ULONG)CatCompArray[ *Tags ].cca_Str;\n\n"
  88.                "}\n"
  89.                "\n"
  90.                "void LocalizeList( struct MinList *List )\n"
  91.                "{\n"
  92.                "\tstruct Node\t*node;\n\n"
  93.                "\tfor( node = (struct Node *)List->mlh_Head; node->ln_Succ; node = node->ln_Succ )\n"
  94.                "\t\tnode->ln_Name = (char *)CatCompArray[ (ULONG)node->ln_Name ].cca_Str;\n"
  95.                "}\n"
  96.                "\n"
  97.                "void LocalizeGadgets( struct NewGadget *ng, ULONG *tags, UWORD *kinds, UWORD num )\n"
  98.                "{\n"
  99.                "\tUWORD\tcnt;\n\n"
  100.                "\tfor( cnt = 0; cnt < num; cnt++ ) {\n"
  101.                "\t\tif( ng->ng_GadgetText )\n"
  102.                "\t\t\tng->ng_GadgetText = CatCompArray[ (ULONG)ng->ng_GadgetText ].cca_Str;\n"
  103.                "\t\tLocalizeTags( tags, *kinds++ );\n"
  104.                "\t\twhile( *tags++ );\n"
  105.                "\t\tng++;\n"
  106.                "\t}\n"
  107.                "}\n"
  108.                "\n"
  109.                "void LocalizeMenus( struct NewMenu *menu )\n"
  110.                "{\n"
  111.                "\twhile( menu->nm_Type != NM_END ) {\n"
  112.                "\t\tif( menu->nm_Label != NM_BARLABEL )\n"
  113.                "\t\t\tmenu->nm_Label = (STRPTR)CatCompArray[ (ULONG)menu->nm_Label ].cca_Str;\n"
  114.                "\t\tif( menu->nm_CommKey )\n"
  115.                "\t\t\tmenu->nm_CommKey = (STRPTR)CatCompArray[ (ULONG)menu->nm_CommKey ].cca_Str;\n"
  116.                "\t\tmenu++;\n"
  117.                "\t}\n"
  118.                "}\n"
  119.                "\n"
  120.                "void LocalizeITexts( struct IntuiText *txt, UWORD cnt )\n"
  121.                "{\n"
  122.                "\twhile( cnt-- ) {\n"
  123.                "\t\ttxt->IText = (UBYTE *)CatCompArray[ (ULONG)txt->IText ].cca_Str;\n"
  124.                "\t\ttxt++;\n"
  125.                "\t}\n"
  126.                "}\n"
  127.                "\n"
  128.                "UBYTE GetActivationKey( STRPTR Text )\n"
  129.                "{\n"
  130.                "\twhile( *Text++ != '_' )\n"
  131.                "\t\tif( *Text == '\\0' )\n"
  132.                "\t\t\treturn( 0 );\n"
  133.                "\n\treturn( *Text );\n"
  134.                "}\n" );
  135. }
  136. ///
  137.  
  138.